package com.backend.utils;

import com.backend.utils.Http.HttpUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.qiniu.util.StringUtils;

import java.util.logging.Logger;

public class UserManageUtils {
    private static final String USER_MANAGER_DOMAIN = "http://127.0.0.1:8090";

    private static final String GET_USER_INFO_BY_ID = "%s/background/get_user_info_by_id/?user_id=%s";
    private static final String GET_USERS_INFO_BY_IDS = "%s/background/get_user_info_by_ids/?user_ids=%s";
    private static final String GET_SCHOOL_INFO = "%s/background/get_educations_info/?province=%s&city=%s";

    private static String getUserManagerDomain() {
        return USER_MANAGER_DOMAIN;
    }

    public static JsonNode getUserInfoById(Integer user_id) {
        String url = String.format(GET_USER_INFO_BY_ID, getUserManagerDomain(),user_id);
        JsonNode jsonNode = HttpUtils.HttpGetJsonNode(url);
        Logger.getGlobal().info("userInfo: " + CommonStringUtils.safeString(jsonNode));
        return jsonNode;
    }

    public static String getGetUsersInfoByIds(String user_ids){
        String url = String.format(GET_USERS_INFO_BY_IDS,getUserManagerDomain(),user_ids);
        String res = HttpUtils.HttpGetString(url);
        if(StringUtils.isNullOrEmpty(res)){
            res = "{}";
        }
        return res;
    }

    public static String getSchoolsInfo(String province,String city){
        String url = String.format(GET_SCHOOL_INFO,getUserManagerDomain(),province,city);
        String res = HttpUtils.HttpGetString(url);
        if(StringUtils.isNullOrEmpty(res)){
            res = "[]";
        }
        return res;
    }


}
